package edu.bit.basic.map;

import java.util.Collection;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

public class MyHashMap<K, V> implements Map<K, V> {
    private int size;
    static final int DEFAULT_SIZE = 10;
    private class Node<K, V> {
        private K key;
        private V value;
        private final int hash;
        private Node<K, V> next;

        public Node (K key, V value, int hash, Node<K, V> next) {
            this.key = key;
            this.value = value;
            this.hash = hash;
            this.next = next;
        }

        public K getKey() {return this.key;}
        public V getValue() {return this.value;}

        public int getHash() {
            return hash;
        }

        public Node<K, V> getNext() {
            return next;
        }

        public void setKey(K key) {
            this.key = key;
        }

        public void setValue(V value) {
            this.value = value;
        }

        public void setNext(Node<K, V> next) {
            this.next = next;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Node<?, ?> node = (Node<?, ?>) o;
            return hash == node.hash &&
                    Objects.equals(key, node.key) &&
                    Objects.equals(value, node.value);
        }

        @Override
        public int hashCode() {
            return Objects.hash(key) ^ Objects.hash(value);
        }

    }

    private Node<K, V>[] elementData;
    private int modeCount;


    public MyHashMap () {

    }


    static final private int hash(Object key) {
        int hash = Objects.hash(key);
        return hash ^ hash >>> 16;
    }

    static final int indexFor(int hash, int length) {
        return hash&(length-1);
    }
    @Override
    public int size() {
        return this.size;
    }

    @Override
    public boolean isEmpty() {
        return this.size == 0;
    }

    @Override
    public boolean containsKey(Object o) {
        return false;
    }

    @Override
    public boolean containsValue(Object o) {
        return false;
    }

    @Override
    public V get(Object o) {
        return null;
    }

    @Override
    public V put(K k, V v) {
        return null;
    }

    void putVal(int hash, K k, V v) {
        if(elementData == null) {

        }
    }

    void resize() {
        if(elementData == null) {
            elementData = new Node[DEFAULT_SIZE];
        } else {
            //扩容
            newData
        }
    }

    @Override
    public V remove(Object o) {
        return null;
    }

    @Override
    public void putAll(Map<? extends K, ? extends V> map) {

    }

    @Override
    public void clear() {

    }

    @Override
    public Set<K> keySet() {
        return null;
    }

    @Override
    public Collection<V> values() {
        return null;
    }

    @Override
    public Set<Entry<K, V>> entrySet() {
        return null;
    }
}
